	# adress
	lui   s1,0xFFFFF
	
switled:                                                                         	
loadSw:	
	# load sw[7:0] --> a1
	lw   s0,0x70(s1)
	andi  a1,s0,0xFF
	# load sw[15:8] --> a2
	srli s0,s0,8 
	andi  a2,s0,0xFF
	# load sw[23:21] --> a3
	srli s0,s0,13
	andi  a3,s0,0x7

# tranfrom numA to correct format 	
tranNumA:
	srli t3,a1,7
	andi t3,t3,1
	beq  t3,zero,tranNumB
	addi a1,a1,-0x80
	xori a1,a1,-1
	addi a1,a1,1
	
# tranfrom numB to correct format 
tranNumB:
	srli t3,a2,7
	andi t3,t3,1
	beq  t3,zero,operatorSelect
	addi a2,a2,-0x80
	xori a2,a2,-1
	addi a2,a2,1

# operator select	
operatorSelect:	
	addi a4,zero,0
	beq  a3,a4,nullOperation
	addi a4,zero,1
	beq  a3,a4,addOperation
	addi a4,zero,2
	beq  a3,a4,subOperation
	addi a4,zero,3
	beq  a3,a4,andOperation
	addi a4,zero,4
	beq  a3,a4,orOperation
	addi a4,zero,5
	beq  a3,a4,sllOperation
	addi a4,zero,6
	beq  a3,a4,sraOperation
	addi a4,zero,7
	beq  a3,a4,mulOperation
	
nullOperation:
	addi t2,zero,0
	jal zero,switled
addOperation:	
	add t2,a1,a2
	jal zero,output		
subOperation:
	sub t2,a1,a2
	jal zero,output
andOperation:
	and t2,a1,a2
	jal zero,output
orOperation:
	or t2,a1,a2
	jal zero,output
sllOperation:
	sll t2,a1,a2
	jal zero,output
sraOperation:
	sra t2,a1,a2
	jal zero,output
mulOperation:  
	# init result
	addi t2,zero,0
	
	blt a2,zero,minus
	
	# if numB is positive
	positive:
	beq a2,zero,output
	add t2,t2,a1
	addi a2,a2,-1
	jal zero,positive
	
	# if numB is minus
	minus:
	beq a2,zero,output
	sub t2,t2,a1
	addi a2,a2,1
	jal zero,minus

output:	
	sw   t2,0x60(s1)          # write led	
    sw   t2,0x00(s1)          # write tube	
	jal zero,switled

